             
import java.awt.BasicStroke;
import java.awt.Button;
import java.awt.Checkbox;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.Insets;
import java.awt.Label;
import java.awt.Panel;
import java.awt.Scrollbar;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.AdjustmentEvent;
import java.awt.event.AdjustmentListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.geom.Ellipse2D;

import javax.swing.JApplet;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.text.JTextComponent;


public class two_bodies_2 extends JApplet implements Runnable, AdjustmentListener, ItemListener{
	
	Thread t=null;
	
	Button startButton, instrButton;
	Checkbox lineOn, orbitOn, graphButton;
    JLabel angmomLabel, energyLabel, mass1Label, mass2Label, eccentricityLabel, semmajLabel;
    JLabel slide1Label, slide1Value, slide2Label, slide2Value, slide3Label, slide3Value;
    JLabel eccentricityOutput, semmajOutput;
    JTextField angmomInput, energyInput, mass1Input, mass2Input;
    Scrollbar slide1,slide2,slide3;
    JTextComponent _imaginary,_instructions;
    
	boolean run_sup_PC=true;
	boolean stop_anim=false;
	boolean line = false;
	boolean orbit = false;
	boolean graph_on = false;
	boolean graph_drawn=false;
	int w=getWidth();
	int h=getHeight();
	double graph_scale=2E19;
	double prev_x_line=0;
	double mass1=5.9742E24,mass2=4.8685E24;
	double reduced_mass=mass1*mass2/(mass1+mass2);
	double x1=0,x2=0,y1=0,y2=0;
	double prev_x1,prev_x2,prev_y1,prev_y2;
	double CMx,CMy;
	double Xt=0,Yt=0;
	double nextX,nextY;
	double VXt=0,VYt=2.1;
	double nextVX,nextVY;
	double deltatheta=0.01;
	double ang=0;
	double G=6.67300E-11;
	double constant_V=G*(mass1+mass2);
	double constant_c=G*mass1*mass2;
	double energy = - 2.76801E21;
	double angular_momentum=3.66179E40;
	double ecc=Math.pow((1+2*energy*angular_momentum*angular_momentum/(reduced_mass*constant_c*constant_c)), .5);
	double r0=angular_momentum*angular_momentum/(reduced_mass*constant_c);
	double r;
	double ref_dist=r0/(1-ecc*Math.cos(70));
	
	int size=10;
	short once_l=0,once_o=0;
	double scale=.1E16;
	public void init()
	{
		gui();
		t=new Thread(this);
		t.start();
	}
	public void paint(Graphics g)
	{
		if(run_sup_PC)
		{
			super.paintComponents(g);
			Graphics2D g3 = (Graphics2D) g;
			g3.setColor(Color.BLACK);
			g3.fillRect(0, 0, w, h);
		}
		Graphics2D g2= (Graphics2D) g;
		if(graph_on)
		{
			g2.setClip(0, 0, 2*w/3-15,h);
		}
		g2.setColor(Color.BLACK);
		Ellipse2D.Double ell=new Ellipse2D.Double(prev_x1-size/2,prev_y1-size/2,size,size);
		g2.fill(ell);
		ell=new Ellipse2D.Double(prev_x2-size/2,prev_y2-size/2,size,size);
		g2.fill(ell);
		g2.setColor(Color.GREEN);
		ell=new Ellipse2D.Double(x1-size/2,y1-size/2,size,size);
		g2.fill(ell);
		g2.setColor(Color.RED);
		ell=new Ellipse2D.Double(x2-size/2,y2-size/2,size,size);
		g2.fill(ell);
		
		g2.setColor(Color.WHITE);
		ell = new Ellipse2D.Double(CMx-2,CMy-2,4,4);
		g2.fill(ell);
		
		if(orbit)
		{
			double major1=r0*mass1/((mass1+mass2)*(1-ecc*ecc)*(scale));
			double major2=r0*mass2/((mass1+mass2)*(1-ecc*ecc)*(scale));
			double minor1=major1*Math.sqrt(1-ecc*ecc);
			double minor2=major2*Math.sqrt(1-ecc*ecc);
			ell=new Ellipse2D.Double((CMx-major1*(1+ecc)),CMy-minor1,2*major1,2*minor1);
			g2.setColor(Color.WHITE);
			g2.draw(ell);
			ell=new Ellipse2D.Double((CMx-major2*(1-ecc)),CMy-minor2,2*major2,2*minor2);
			g2.setColor(Color.WHITE);
			g2.draw(ell);
			once_o=1;
		}
		else if(once_o==1)
		{
			g2.setColor(Color.BLACK);
			double major1=r0*mass1/((mass1+mass2)*(1-ecc*ecc)*(scale));
			double major2=r0*mass2/((mass1+mass2)*(1-ecc*ecc)*(scale));
			double minor1=major1*Math.sqrt(1-ecc*ecc);
			double minor2=major2*Math.sqrt(1-ecc*ecc);
			ell=new Ellipse2D.Double((CMx-major1*(1+ecc)),CMy-minor1,2*major1,2*minor1);
			g2.draw(ell);
			ell=new Ellipse2D.Double((CMx-major2*(1-ecc)),CMy-minor2,2*major2,2*minor2);
			g2.draw(ell);
			once_o=90;
		
		}
		if(line)
		{
			g2.setColor(Color.BLACK);
			g2.drawLine((int)prev_x1, (int)prev_y1, (int)prev_x2, (int)prev_y2);
			g2.setColor(Color.ORANGE);
			g2.drawLine((int)x1, (int)y1, (int)x2, (int)y2);
			once_l=1;
		}
		else if(once_l==1)
		{
			g2.setColor(Color.BLACK);
			g2.drawLine((int)prev_x1, (int)prev_y1, (int)prev_x2, (int)prev_y2);
			once_l=90;
		}
		/*graph section begin*/
		if(graph_on){
			g2.setClip(2*w/3-15,0,w,h);
			if(!graph_drawn)
			{
				g2.setColor(Color.darkGray);
				g2.fillRect(2*w/3-15, 0, w, h);
				g2.setColor(Color.green);
				//the axis
				g2.setStroke(new BasicStroke(2));
				g2.drawLine(2*w/3,h/15 ,2*w/3 , 7*h/8);
				g2.drawLine(2*w/3,113*h/240 ,w-2, 113*h/240);
				//arrow on axis
				g2.drawLine(2*w/3,h/15 ,2*w/3-3,h/15+3 );
				g2.drawLine(2*w/3,h/15 ,2*w/3+3,h/15+3 );
				g2.drawLine(2*w/3 , 7*h/8,2*w/3-3 , 7*h/8-3);
				g2.drawLine(2*w/3 , 7*h/8,2*w/3+3 , 7*h/8-3);
				g2.drawLine(w-2, 113*h/240,w-5, 113*h/240-3);
				g2.drawLine(w-2, 113*h/240,w-5, 113*h/240+3);
				g2.setStroke(new BasicStroke(1));
				//labelling
				g2.setColor(Color.blue.brighter().brighter());
				g2.fillRect(4*w/5-13, h/12-13,w/3-10 , h/36+18);
				g2.setColor(Color.WHITE);
				g2.drawString("x-axis : Distance of Reduced Mass from Center",4*w/5-10 , h/12);
				g2.drawString("y-axis : Effective Potential Energy",4*w/5-10 , h/9);
			}
			//plot the curve
			//taking 10 px= 1 therefore 1 px=0.1 units
			double y_pt,x_pt;
			double last_x,last_y;
			double fx;
			double graph_unit_scale=1E15;
			last_x=1;
			last_y=-constant_c/(last_x*graph_unit_scale)+angular_momentum*angular_momentum/(2*reduced_mass*last_x*last_x*graph_unit_scale*graph_unit_scale);
			double x_initial=2;
			double x_final=w/3-2;
			double y_line =(int)(113*h/240-energy/graph_scale);
			double x_line=0;
			double diff=1E20;
			g2.setColor(Color.darkGray);
			ell=new Ellipse2D.Double((int)(2*w/3+prev_x_line-size/2), y_line-size/2, size, size);
			g2.fill(ell);
			g2.setColor(Color.MAGENTA);
			for(x_pt=x_initial;x_pt<x_final;x_pt++)
			{
				if(Math.abs(r-x_pt*graph_unit_scale)<diff)
				{
					diff=r-x_pt*graph_unit_scale;
					x_line=x_pt;
				}
				if(!graph_drawn)
				{
					fx=-constant_c/(x_pt*graph_unit_scale)+angular_momentum*angular_momentum/(2*reduced_mass*x_pt*x_pt*graph_unit_scale*graph_unit_scale);
					y_pt=113*h/240-fx/graph_scale;
					g2.drawLine((int)last_x+2*w/3,(int)last_y,(int)x_pt+2*w/3,(int)y_pt);
					//System.out.println(r-x_pt*graph_unit_scale);
					last_y=y_pt;
					last_x=x_pt;	
				}
				if(x_pt>x_final/2)
				{
					graph_unit_scale*=1+Math.atan(Math.pow((x_pt-x_final/2)/50,2))/(100*Math.PI/2);
				}
			}
			graph_drawn=true;
			/*graph section end*/
			
			/*energy line start*/
			g2.setColor(Color.ORANGE);
			ell=new Ellipse2D.Double((int)(2*w/3+x_line-size/2), y_line-size/2, size, size);
			prev_x_line=x_line;
			g2.fill(ell);
			
			g2.drawLine(2*w/3,(int) y_line, w,(int) y_line);
			
			
			/*energy line end*/
		}
		
		
		
		run_sup_PC=false;
	}
	public void gui()
	{
		Color  panelbg=Color.LIGHT_GRAY;
        Color  panelfg=Color.white;
		Color  buttonfg=Color.black;
        Font buttonFont = new Font ("Helvetica",Font.BOLD, 11);
        
        Panel pa = new Panel();
        add("North",pa);
        pa.setBackground(Color.BLACK);
        
        JLabel appletLabel = new JLabel("Motion of two masses under gravitational force");
        appletLabel.setForeground(Color.RED);
        appletLabel.setFont(new Font("Times New Roman", Font.BOLD, 20));
        pa.add(appletLabel);
        
        
        //all panel components
        //line checkboc
        lineOn = new Checkbox ("  Show Line  ",false);
        lineOn.setForeground(Color.black);
        lineOn.addItemListener(this);
        
        //orbit checkbox
        orbitOn = new Checkbox (" Show Orbit  ",false);
        orbitOn.setForeground(Color.black);
        orbitOn.addItemListener(this);
        
        //graph checkbox
        graphButton = new Checkbox ("Show Graph",false);
        //graphButton.setBackground(Color.pink);
        graphButton.setForeground(Color.black);
        graphButton.addItemListener(this);
        
        //start button
        startButton = new Button (" Simulate ");
        startButton.setBackground(Color.pink);
        startButton.setForeground(Color.black);
        
        //instructions button
        instrButton = new Button (" Instructions ");
        instrButton.setBackground(Color.pink);
        instrButton.setForeground(Color.black);
        
        angmomLabel = new JLabel("<html>Angular Momentum (x10<sup>40</sup>)</html>", Label.LEFT);
		angmomInput = new JTextField("3.66179");
		energyLabel = new JLabel("<html>(-ve)Energy (x-10<sup>21</sup>)</html>", Label.LEFT);
		energyInput = new JTextField("2.76801");
		
		mass1Label = new JLabel("<html>Mass1 (x10<sup>24</sup>)</html>", Label.LEFT);
		mass1Label.setMinimumSize(new Dimension(200,50));
		mass1Input = new JTextField("5.9742");
		mass2Label = new JLabel("<html>Mass2 (x10<sup>24</sup>)</html>", Label.LEFT);
		mass2Input = new JTextField("4.8685");
        
		eccentricityLabel = new JLabel("Eccentricity", Label.LEFT);
		eccentricityLabel.setMinimumSize(new Dimension(200,50));
		eccentricityOutput = new JLabel(""+(double)Math.round(ecc * 1000000) / 1000000);
		semmajLabel = new JLabel("<html>Semi-major axis (x10<sup>15</sup>)</html>", Label.LEFT);
		semmajOutput = new JLabel(""+(double)Math.round(((r0/1-ecc)/(2*1E15)) * 1000000) / 1000000);
		eccentricityOutput.setForeground(Color.RED);
		semmajOutput.setForeground(Color.RED);
        //appletLabel.setFont(new Font("Times New Roman", Font.BOLD, 20));
		
		//orbit scale slider
		int initialValue=11;
		slide1 = new  Scrollbar(Scrollbar.HORIZONTAL, initialValue, 1, 1, 22);
		slide1Value = new JLabel("<html>10<sup>15</sup></html>");
		slide1Label = new JLabel("Orbit Scale: ", Label.LEFT);
		slide1.addAdjustmentListener(this);
		
		//planets speed slider
		int initialValue2=10;
		slide2 = new  Scrollbar(Scrollbar.HORIZONTAL, initialValue2, 1, 1, 20);
		slide2Value = new JLabel("0.01");
		slide2Label = new JLabel("Speed: ", Label.LEFT);
		slide2.addAdjustmentListener(this);
		
		//graph scale slider
		int initialValue3=2;
		slide3 = new  Scrollbar(Scrollbar.HORIZONTAL, initialValue3, 1, 1, 16);
		slide3Label = new JLabel("Graph Scale: ", Label.LEFT);
		slide3Value = new JLabel("<html>10<sup>15</sup></html>");
		slide3.addAdjustmentListener(this);
		
		//making panels and adding components
		Panel baap = new Panel(new GridBagLayout());
        baap.setBackground(panelbg);
        add("South",baap);
		
        GridBagConstraints baapcp = new GridBagConstraints();
        baapcp.gridx = 0;
        baapcp.gridy = 0;
        Panel pparent = new Panel(new GridBagLayout());
        baap.add(pparent,baapcp);
        
        baapcp.gridx = 0;
        baapcp.gridy = 1;
        baapcp.anchor = GridBagConstraints.WEST;
        Panel pparent2 = new Panel(new GridBagLayout());
        baap.add(pparent2,baapcp);
        
        GridBagConstraints cp = new GridBagConstraints();
        cp.gridx = 0;
		cp.gridy = 0;
		//cp.anchor = GridBagConstraints.WEST;
		pparent.add(lineOn,cp);
		
		cp.gridx = 0;
		cp.gridy = 1;
		//cp.anchor = GridBagConstraints.WEST;
		pparent.add(orbitOn,cp);
		
		cp.gridx = 0;
		cp.gridy = 2;
		//cp.anchor = GridBagConstraints.WEST;
		pparent.add(graphButton,cp);
		
		cp.gridx = 1;
		cp.gridy = 0;
		cp.insets = new Insets(0, 100, 0, 0);
		pparent.add(angmomLabel,cp);
		cp.gridx = 1;
		cp.gridy = 1;
		pparent.add(energyLabel,cp);
		cp.gridx = 1;
		cp.gridy = 2;
		pparent.add(eccentricityLabel,cp);
		
		cp.gridx = 2;
		cp.gridy = 0;
		cp.ipadx = 40;
		cp.insets = new Insets(0, 0, 0, 0);
		pparent.add(angmomInput,cp);
		cp.gridx = 2;
		cp.gridy = 1;
		pparent.add(energyInput,cp);
		cp.gridx = 2;
		cp.gridy = 2;
		pparent.add(eccentricityOutput,cp);
		
		
		cp.ipadx = 0;
		
		cp.gridx = 3;
		cp.gridy = 0;
		cp.insets = new Insets(0, 20, 0, 0);
		pparent.add(mass1Label,cp);
		cp.gridx = 3;
		cp.gridy = 1;
		pparent.add(mass2Label,cp);
		cp.gridx = 3;
		cp.gridy = 2;
		pparent.add(semmajLabel,cp);
		cp.gridx = 4;
		cp.gridy = 0;
		cp.ipadx = 40;
		cp.insets = new Insets(0, 0, 0, 0);
		pparent.add(mass1Input,cp);
		cp.gridx = 4;
		cp.gridy = 1;
		pparent.add(mass2Input,cp);
		cp.gridx = 4;
		cp.gridy = 2;
		cp.ipadx = 10;
		pparent.add(semmajOutput,cp);
		
		cp.ipadx = 20;
		cp.gridx = 5;
		cp.gridy = 0;
		cp.insets = new Insets(0, 30, 0, 0);
		pparent.add(startButton,cp);
		
		cp.ipadx = 0;
		cp.insets = new Insets(0, 0, 0, 0);
//		cp.gridx = 5;
//		cp.gridy = 0;
//		cp.insets = new Insets(0, 20, 0, 0);
//		pparent.add(eccentricityLabel,cp);
//		cp.gridx = 5;
//		cp.gridy = 1;
//		pparent.add(semmajLabel,cp);
//		cp.gridx = 6;
//		cp.gridy = 0;
//		cp.ipadx = 40;
//		cp.insets = new Insets(0, 0, 0, 0);
//		pparent.add(eccentricityOutput,cp);
//		cp.gridx = 6;
//		cp.gridy = 1;
//		pparent.add(semmajOutput,cp);
//		cp.ipadx = 0;
		
		
		Panel slide1panel = new Panel(new GridLayout(1,2));
		Panel slide2panel = new Panel(new GridLayout(1,2));
		Panel slide3panel = new Panel(new GridLayout(1,2));
		slide1panel.add(slide1Label);
		slide1.setPreferredSize(new Dimension(75,10));
		slide1panel.add(slide1);
		slide2panel.add(slide2Label);
		slide2.setPreferredSize(new Dimension(75,10));
		slide2panel.add(slide2);
		slide3panel.add(slide3Label);
		slide3panel.add(slide3);
		
		GridBagConstraints cp2 = new GridBagConstraints();
        cp2.gridx = 0;
		cp2.gridy = 0;
		cp2.anchor = GridBagConstraints.WEST;
		cp2.insets = new Insets(0, 0, 0, 50);
		pparent2.add(slide3panel,cp2);

		cp2.gridx = 1;
		pparent2.add(slide1panel,cp2);
		
		cp2.gridx = 2;
		pparent2.add(slide2panel,cp2);
		
		cp2.gridx = 3;
		cp2.insets = new Insets(0, 0, 0, 0);
		pparent2.add(instrButton,cp2);
		
		
//		graphButton.addActionListener(new ActionListener() {
//			@Override
//			public void actionPerformed(ActionEvent arg0) {
//				graph_on= !graph_on;
//				run_sup_PC = true;
//				graph_drawn=false;
//			}
//			
//		});
		
//		orbitOn.addActionListener(new ActionListener() {
//			@Override
//			public void actionPerformed(ActionEvent arg0) {
//				if(!orbit) {
//			        orbit = true;                             // toggle Boolean
//			        orbitOn.setLabel(" Hide Orbit ");             // toggle label
//				}
//				else{
//					orbit = false;                             // toggle Boolean
//					orbitOn.setLabel(" Show Orbit ");             // toggle label
//				}
//			}
//		});
		
		startButton.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent arg0) {
				graph_drawn=false;
				angular_momentum = Double.parseDouble(angmomInput.getText()) * 1E40;
				energy = -1 * Double.parseDouble(energyInput.getText()) * 1E21;
				mass1 =  Double.parseDouble(mass1Input.getText()) * 1E24;
				mass2 =  Double.parseDouble(mass2Input.getText()) * 1E24;
				ecc=Math.pow((1+2*energy*angular_momentum*angular_momentum/(reduced_mass*constant_c*constant_c)), .5);
				r0=angular_momentum*angular_momentum/(reduced_mass*constant_c);
				eccentricityOutput.setText(""+(double)Math.round(ecc * 1000000) / 1000000);
				semmajOutput.setText(""+(double)Math.round(((r0/1-ecc)/(2*1E15)) * 1000000) / 1000000);
				ref_dist=r0/(1-ecc*Math.cos(70));
				if(Double.isNaN(ecc))
				{
					stop_anim=true;
					calculate_cordinates();
					run_sup_PC = true;
					repaint();
					ang=0;
					eccentricityOutput.setText("---");
					JOptionPane.showMessageDialog(_imaginary,"The given Energy and Angular Momentum result in an imaginary eccentricity.","Error",JOptionPane.ERROR_MESSAGE);	
					
				}
				else if(ecc>1){
					stop_anim=true;
					calculate_cordinates();
					run_sup_PC = true;
					repaint();
					ang=0;
					eccentricityOutput.setText(""+(double)Math.round(ecc * 1000000) / 1000000);
					JOptionPane.showMessageDialog(_imaginary,"Resulting Orbit is unbounded since eccentricity > 1.","Error",JOptionPane.ERROR_MESSAGE);
				}
				else
				{
					if(Double.isNaN(ang))
						ang=0;
					stop_anim=false;
				}
				run_sup_PC = true;
			}
		});
		
		instrButton.addActionListener(new ActionListener()
		{	
			@Override
			public void actionPerformed(ActionEvent arg0)
			{
				String msg = "<html><b>Instructions to use this applet</b>" +
						"<ol><li>Orbits of two bodies are plotted for the chosen value of :</li>" +
						"<ol type='a'><li>Total Angular Momentum and Energy in center of mass frame.</li>" +
						"<li>Mass of the two bodies</li>" +
						"</ol><li>Energy diagram of the reduced mass and its position on this diagram<br /> can be viewed by selecting 'Show graph'.</li>" +
						"<li>Scale for the orbits and the energy diagram can both be changed separately <br />using the 'Orbit Scale' and 'Graph scale' scroll-bars respectively.</li>" +
						"<li>Speed of the animation can be varied using 'Speed' scroll-bar.</li>" +
						"<li>SI units are used - </li>" +
						"<ul><li>Angular Momentum :  <b>kg m<sup>2</sup>/s</b></li>" +
						"<li>Energy : <b>kg m/s<sup>2</sup></b></li>" +
						"<li>Mass : <b>kg</b></li>" +
						"<li>Distance : <b>m</b></li>" +
						"</ul></ol></html>";
				        JLabel label = new JLabel(msg);
				        label.setFont(new Font("serif", Font.PLAIN, 14));
				JOptionPane.showMessageDialog(_instructions,label,"Instructions",JOptionPane.INFORMATION_MESSAGE);
			}
		});
		
		
	}
	
	public void itemStateChanged(ItemEvent e){
		Object source = e.getItemSelectable();
		if(source==lineOn){
			line = !line;
		}
		if(source==orbitOn){
			orbit=!orbit;
		}
		if(source==graphButton){
			graph_on=!graph_on;
			run_sup_PC=true;
			graph_drawn=false;
		}
		
	}
	
	@Override
	public void adjustmentValueChanged(AdjustmentEvent arg0) {
		if(arg0.getAdjustable() == slide1){
			int val = slide1.getValue();
			System.out.println("val: "+val);
			double exp = 14.0 + 2.0*( (double)val - 1 )/20.0;
			scale=Math.pow(10, exp);
			exp = (double)Math.round(exp * 100) / 100;
			this.slide1Value.setText("<html>10<sup>"+exp+"</sup></html>");
			run_sup_PC=true;
		}
		
		if(arg0.getAdjustable() == slide2){
			int val2 = slide2.getValue();
			
			if(val2==10){
				this.slide2Value.setText("0.01");
				deltatheta=0.01;
			}
			if(val2<10){
				this.slide2Value.setText(""+(double)Math.round(val2*0.001*1000)/1000);
				deltatheta = (double)Math.round(val2*0.001*1000)/1000;
			}
			if(val2>10){
				this.slide2Value.setText(""+(val2-9)*0.01);
				deltatheta = (val2-9)*0.01;
			}
			//System.out.println("val2: "+val2);
			run_sup_PC=true;
		}
		
		if(arg0.getAdjustable() == slide3){
			int val3 = slide3.getValue();
			graph_scale=val3*1E19;
			run_sup_PC=true;
		}
		
		graph_drawn=false;
	}
	
	public void run()
	{
		while(true)
		{
			while(stop_anim)
			{
				try
				{
					Thread.sleep(10);
				}
				catch (InterruptedException ie)
				{
					System.out.println(ie.getMessage());
				}
			}
			try
			{
				Thread.sleep(10);
			}
			catch (InterruptedException ie)
			{
				System.out.println(ie.getMessage());
			}
			calculate_cordinates();
			ang=ang+ref_dist*ref_dist*deltatheta/(r*r);
			ang=ang%(2*Math.PI);
			repaint();
		}
	}
	private void calculate_cordinates() {
		if(w!=getWidth() || h!=getHeight())
		{
			run_sup_PC=true;
			graph_drawn=false;
			w=getWidth();
			h=getHeight();
		}
		//System.out.println("ecc: "+ecc);
		if(graph_on == false){
			CMx=w/2;
			CMy=h/2;
		}
		else{
			CMx=w/3;
			CMy=h/2;
		}
		
		r=r0/(1-ecc*Math.cos(ang));
		Xt=Math.cos(ang)*r/scale;
		Yt=Math.sin(ang)*r/scale;
		prev_x1=x1;
		prev_x2=x2;
		prev_y1=y1;
		prev_y2=y2;
		x1=CMx+(Xt*mass2/(mass1+mass2));
		y1=CMy+(Yt*mass2/(mass1+mass2));
		x2=CMx-(Xt*mass1/(mass1+mass2));
		y2=CMy-(Yt*mass1/(mass1+mass2));
		}
	
}